package com.fwmagic.springcloud.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @description:
 * @author: fangwei
 * @date: 2022/4/22
 **/
@RestController
@Slf4j
public class FlowLimitController {

    @GetMapping("/testA")
    public String testA() {
        return "----testA";
    }

    @GetMapping("/testB")
    public String testB() {
        log.info("----testB");
        return "----testB";
    }

    @GetMapping("/testC")
    public String testC() {
        log.info("----testC");
        return "----testC";
    }

    @GetMapping("/testD")
    public String testD() {
        /*try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }*/
        System.out.println(1 / 0);
        return "----testD";
    }

    @GetMapping("/testHotKey")
    @SentinelResource(value = "testHoyKey", blockHandler = "dealHandler_testHoyKey")
    public String testHotKey(
            @RequestParam(value = "p1", required = false) String p1,
            @RequestParam(value = "p2", required = false) String p2
    ) {
        System.out.println(1/0);
        return "----testHoyKey";
    }

    public String dealHandler_testHoyKey(String p1, String p2, BlockException exception) {
        return "-----dealHandler_testHoyKey";
    }
}
